home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / isigns50.zip / PRINTER2.PAS < prev    next >
Pascal/Delphi Source File  |  1989-09-29  |  4KB  |  119 lines

  1. {      This Unit is a replacement for the Printer unit that   }
  2. { came with Turbo Pascal Version 4.  It's purpose is two      }
  3. { fold.  It will allow a user to change the printer port that }
  4. { the LST file is writing to on the fly.  This takes the      }
  5. { place of LstOutPtr and the routine on page 369 of the Turbo }
  6. { Pascal Version 3 manual.  The second purpose of this unit   }
  7. { is that it will also circumvent DOS's stripping of a Ctrl-Z }
  8. { ($1A, the End Of File character) when writing to the        }
  9. { printer as an ASCII device.  Ctrl-Z was usually sent as     }
  10. { part of a graphics string to a printer.  In version 3.0 of  }
  11. { Turbo Pascal an ASCII device was opened in binary mode, and }
  12. { in version 4 an ASCII device is opened in ASCII mode and    }
  13. { DOS thus strips a Ctrl-Z.                                   }
  14. {                                                             }
  15. {      This also provides a good example of a Text file       }
  16. { device driver.                                              }
  17. {                                                             }
  18. {      Type this to a file called PRINTER2.PAS                }
  19.  
  20. Unit Printer2;
  21.  
  22. Interface
  23.  
  24. Uses DOS;                                  { for using INTR() }
  25.  
  26. Var
  27.   LST : Text;                      { Public LST file variable }
  28.  
  29. Procedure SetPrinter( Port:Byte );
  30. {      SetPrinter sets the printer number to Port where Port  }
  31. { is 'n' in 'LPTn'.  ie.  To write to LPT1: SetPrinter(1),    }
  32. { for LPT2: SetPrinter(2).  SetPrinter changes the Port that  }
  33. { subsequent Write operations will write to.  This lets you   }
  34. { change the printer that you are printing to on the fly.     }
  35.  
  36. Implementation
  37.  
  38. {      The following routines MUST be FAR calls because they  }
  39. { are called by the Read and Write routines.  (They are not   }
  40. { Public (in the implementation section ) because they should }
  41. { only be accessed by the Read and Write routines.            }
  42.  
  43. {$F+}
  44.  
  45. {      LSTNoFunction performs a NUL operation for a Reset or  }
  46. { Rewrite on LST (Just in case)                               }
  47.  
  48. Function LSTNoFunction( Var F: TextRec ): integer;
  49. Begin
  50.   LSTNoFunction := 0;                    { No error           }
  51. end;
  52.  
  53. {      LSTOutputToPrinter sends a the output to the Printer   }
  54. { port number stored in the first byte or the UserData area   }
  55. { of the Text Record.                                         }
  56.  
  57. Function LSTOutputToPrinter( Var F: TextRec ): integer;
  58. var
  59.   Regs: Registers;
  60.   P : word;
  61. begin
  62.   With F do
  63.   Begin
  64.     P := 0;
  65.     Regs.AH := 16;
  66.     While (P < BufPos) and ((regs.ah and 16) = 16) do
  67.     Begin
  68.       Regs.AL := Ord(BufPtr^[P]);
  69.       Regs.AH := 0;
  70.       Regs.DX := UserData[1];
  71.       Intr($17,Regs);
  72.       Inc(P);
  73.     end;
  74.     BufPos := 0;
  75.   End;
  76.   if (Regs.AH and 16) = 16 then
  77.     LSTOutputToPrinter := 0              { No error           }
  78.    else
  79.      if (Regs.AH and 32 ) = 32 then
  80.        LSTOutputToPrinter := 159         { Out of Paper       }
  81.    else
  82.        LSTOutputToPrinter := 160;        { Device write Fault }
  83. End;
  84.  
  85. {$F-}
  86.  
  87. {      AssignLST both sets up the LST text file record as     }
  88. { would ASSIGN, and initializes it as would a RESET.  It also }
  89. { stores the Port number in the first Byte of the UserData    }
  90. { area.                                                       }
  91.  
  92. Procedure AssignLST( Port:Byte );
  93. Begin
  94.   With TextRec(LST) do
  95.     begin
  96.       Handle      := $FFF0;
  97.       Mode        := fmOutput;
  98.       BufSize     := SizeOf(Buffer);
  99.       BufPtr      := @Buffer;
  100.       BufPos      := 0;
  101.       OpenFunc    := @LSTNoFunction;
  102.       InOutFunc   := @LSTOutputToPrinter;
  103.       FlushFunc   := @LSTOutputToPrinter;
  104.       CloseFunc   := @LSTOutputToPrinter;
  105.       UserData[1] := Port - 1;  { We subtract one because }
  106.   end;                          { Dos Counts from zero.   }
  107. end;
  108.  
  109.  
  110. Procedure SetPrinter( Port:Byte ); { Documented above     }
  111. Begin
  112.   With TextRec(LST) do
  113.     UserData[1] := Port - 1;{ We subtract one because DOS }
  114. End;                        { Counts from zero.           }
  115.  
  116. Begin  { Initilization }
  117.   AssignLST( 1 );           { Call assignLST so it works  }
  118. end.                        { like Turbo's Printer unit   }
  119.